package info.brenstar.boxedin.core;

import org.newdawn.slick.*;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;

import info.brenstar.boxedin.collisions.CollisionChecker;
import info.brenstar.boxedin.collisions.CollisionMap;

import java.util.ArrayList;

public abstract class Room {
	
	protected CollisionMap map;
	protected SpriteGroup entities;
	
	public Room() {
		map = new CollisionMap(160,160);
		CollisionChecker.Map = map;
		entities = new SpriteGroup(this);
	}
	
	public abstract void init();
	public abstract void update(GameContainer container, int delta);
	public abstract void render(GameContainer container, Graphics g);
	
	public final void add(Sprite sprite) {
		sprite.init();
		entities.add(sprite);
		map.add(sprite);
	}
	
	//Deprecated use collision maps
	public final Sprite collidesWith(Rectangle rect) {
		
		for (Sprite s : entities.getAll()) {
			Shape mask = s.getMask();
			mask.setX(s.getX());
			mask.setY(s.getY());
			
			if (s.isCollide() && mask != null) {
				if (mask.intersects(rect)) { 
					return s;
				}
			}
			
		}
		
		return null;
	}
	
}
